﻿using System;
using Quadrant.domain.Helpers;
using Quadrant.domain.Models;

namespace Quadrant.domain.Services
{
    public class QuadrantUserServices : BaseServices
    {
        public void Init(Guid userId)
        {
            var insert = false;
            var usr = DB.QuadrantUsers.Find(userId);
            if (usr == null)
            {
                usr = new QuadrantUser { Id = userId };
                DB.QuadrantUsers.Add(usr);
                insert = true;
            }
            usr.LastLoginUtc = DateTime.UtcNow;
            if (DB.SaveChanges() > 0 && insert)
            {
                (new QuadrantServices(this.DB)).InjectQuadrant(usr.Id, 0);
            };

        }
    }
}
